//
//  ByViewUserOperateCustom.m
//  jinpuyiyuan_ios
//
//  Created by pro on 2017/12/8.
//  Copyright © 2017年 mc. All rights reserved.
//

#import "ByViewUserOperateCustom.h"

@implementation ByViewUserOperateCustom
{
    NSArray *_titles;
    NSArray *_places;
}
- (instancetype)init{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.layer.cornerRadius = 4.0;
    }
    return self;
}

- (void)setInfoAry:(NSArray *)infoAry{
    _infoAry = infoAry;
    _titles = _infoAry[0];
    _places = _infoAry[1];
    [self createViews];
}

- (void)createViews{
    CGFloat first_marign = 50;
    CGFloat margin = 20;
    CGFloat code_width = [@"(60s)发送验证" getSizeOfString:14].width + 5;
    CGFloat title_width = [@"手机号码" getSizeOfString:14].width + 5;
    for (int i = 0; i < _titles.count; i ++) {
        UILabel *titleLabel = [[UILabel alloc] init];
        [self addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(30));
            make.top.equalTo(@(first_marign + (30 + margin) * i));
            make.size.mas_equalTo(CGSizeMake(title_width, 30));
        }];
        titleLabel.text = _titles[i];
        titleLabel.font = FONT(14);
        titleLabel.textColor = [UIColor lightGrayColor];
        
        UITextField *tf = [[UITextField alloc] init];
        [self addSubview:tf];
        [tf mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(titleLabel.mas_right);
            make.top.equalTo(titleLabel.mas_top);
            if (i == 0) {
                make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 30 - 60 - code_width - title_width, 30));;
            }else{
                make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 30 - 60 - title_width, 30));;
            }
        }];
        tf.font = FONT(14);
        tf.placeholder = _places[i];
        tf.tag = 10 + i;
        
        // line
        UIView *line = [[UIView alloc] init];
        [self addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(30));
            make.top.equalTo(tf.mas_bottom);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 30 - 60, 1));
        }];
        line.backgroundColor = BY_THEME_COLOR;
        
        if (i == 0) {
            UIButton *codeButton = [[UIButton alloc] init];
            [self addSubview:codeButton];
            [codeButton mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(@(-30));
                make.top.equalTo(tf.mas_top);
                make.size.mas_equalTo(CGSizeMake(code_width, 30));
            }];
            [codeButton setTitle:@"发送验证" forState:UIControlStateNormal];
            [codeButton setTitleColor:BY_THEME_COLOR forState:UIControlStateNormal];
            codeButton.titleLabel.font = FONT(14);
            [codeButton addTarget:self action:@selector(sendCodeAction:) forControlEvents:UIControlEventTouchUpInside];
        }
        
    }
}

#pragma mark - 发送验证码
- (void)sendCodeAction:(UIButton *) button{
    if (self.sendCodeBlock) {
        self.sendCodeBlock(button);
    }
}
@end
